package o;

import com.google.android.exoplayer2.Format;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

final class afj extends afq {
    private a ˋ;
    private amw ॱ;

    class a implements afn, aea {
        private long[] ˊ;
        private long ˋ = -1;
        private long[] ˎ;
        private long ˏ = -1;
        final /* synthetic */ afj ॱ;

        public a(afj o_afj) {
            this.ॱ = o_afj;
        }

        public void ˊ(long j) {
            this.ˋ = j;
        }

        public void ˏ(anc o_anc) {
            o_anc.ˎ(1);
            int ˏॱ = o_anc.ˏॱ() / 18;
            this.ˊ = new long[ˏॱ];
            this.ˎ = new long[ˏॱ];
            for (int i = 0; i < ˏॱ; i++) {
                this.ˊ[i] = o_anc.ॱˎ();
                this.ˎ[i] = o_anc.ॱˎ();
                o_anc.ˎ(2);
            }
        }

        public long ˋ(adv o_adv) throws IOException, InterruptedException {
            if (this.ˏ < 0) {
                return -1;
            }
            long j = -(this.ˏ + 2);
            this.ˏ = -1;
            return j;
        }

        public long ॱ(long j) {
            long ˎ = this.ॱ.ˎ(j);
            this.ˏ = this.ˊ[anr.ˊ(this.ˊ, ˎ, true, true)];
            return ˎ;
        }

        public aea ˏ() {
            return this;
        }

        public boolean ˊ() {
            return true;
        }

        public o.aea.a ˏ(long j) {
            int ˊ = anr.ˊ(this.ˊ, this.ॱ.ˎ(j), true, true);
            long ˏ = this.ॱ.ˏ(this.ˊ[ˊ]);
            aeh o_aeh = new aeh(ˏ, this.ˋ + this.ˎ[ˊ]);
            if (ˏ >= j || ˊ == this.ˊ.length - 1) {
                return new o.aea.a(o_aeh);
            }
            return new o.aea.a(o_aeh, new aeh(this.ॱ.ˏ(this.ˊ[ˊ + 1]), this.ˋ + this.ˎ[ˊ + 1]));
        }

        public long g_() {
            return this.ॱ.ॱ.ˏ();
        }
    }

    afj() {
    }

    public static boolean ॱ(anc o_anc) {
        return o_anc.ˊ() >= 5 && o_anc.ʽ() == 127 && o_anc.ˋॱ() == 1179402563;
    }

    protected void ˏ(boolean z) {
        super.ˏ(z);
        if (z) {
            this.ॱ = null;
            this.ˋ = null;
        }
    }

    private static boolean ˎ(byte[] bArr) {
        return bArr[0] == (byte) -1;
    }

    protected long ˏ(anc o_anc) {
        if (ˎ(o_anc.ˏ)) {
            return (long) ˎ(o_anc);
        }
        return -1;
    }

    protected boolean ˎ(anc o_anc, long j, c cVar) throws IOException, InterruptedException {
        byte[] bArr = o_anc.ˏ;
        if (this.ॱ == null) {
            this.ॱ = new amw(bArr, 17);
            Object copyOfRange = Arrays.copyOfRange(bArr, 9, o_anc.ॱ());
            copyOfRange[4] = Byte.MIN_VALUE;
            List singletonList = Collections.singletonList(copyOfRange);
            cVar.ˏ = Format.ˎ(null, "audio/flac", null, -1, this.ॱ.ˎ(), this.ॱ.ॱॱ, this.ॱ.ˊ, singletonList, null, 0, null);
        } else if ((bArr[0] & 127) == 3) {
            this.ˋ = new a(this);
            this.ˋ.ˏ(o_anc);
        } else if (ˎ(bArr)) {
            if (this.ˋ == null) {
                return false;
            }
            this.ˋ.ˊ(j);
            cVar.ˊ = this.ˋ;
            return false;
        }
        return true;
    }

    private int ˎ(anc o_anc) {
        int i = (o_anc.ˏ[2] & 255) >> 4;
        switch (i) {
            case 1:
                return 192;
            case 2:
            case 3:
            case 4:
            case 5:
                return 576 << (i - 2);
            case 6:
            case 7:
                o_anc.ˎ(4);
                o_anc.ˊˊ();
                i = i == 6 ? o_anc.ʽ() : o_anc.ॱॱ();
                o_anc.ˋ(0);
                return i + 1;
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
                return 256 << (i - 8);
            default:
                return -1;
        }
    }
}
